<?php
/**
 * 货品控制器
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2017/12/29
 * Time: 18:20
 */

namespace App\Http\Controllers\MiniProgram;

use App\Http\Controllers\BaseController;
use App\Http\Logics\MiniProgram\ProductLogic;
use App\Http\Traits\ProductTrait;

class ProductController extends BaseController
{
    use ProductTrait;
    /**
     * @SWG\Get(
     *     path="/product/detail",
     *     tags={"Product"},
     *     description="获取货品详情",
     *     operationId="createProduct",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=false,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="product_id",
     *         in="query",
     *         description="货品ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getProductDetail()
    {
        $product_id = $this->product_id;
        $data = [
            'product_id' => $product_id
        ];
        $response = ProductLogic::getProductDetail($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Get(
     *     path="/product/list",
     *     tags={"Product"},
     *     description="获取货品列表",
     *     operationId="getProductList",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=false,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="limit",
     *         in="query",
     *         description="分页大小",
     *         required=false,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="category_id",
     *         in="query",
     *         description="分类ID",
     *         required=false,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="tag_id",
     *         in="query",
     *         description="标签ID",
     *         required=false,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="cafe_id",
     *         in="query",
     *         description="咖啡馆ID",
     *         required=false,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="limit",
     *         in="query",
     *         description="分页大小",
     *         required=false,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getProductList()
    {
        $category_id = $this->category_id;
        $tag_id = $this->tag_id;
        $limit = $this->limit;
        $cafe_id = $this->cafe_id;
        $data = [
            'category_id' => $category_id,
            'tag_id' => $tag_id,
            'limit' => $limit,
            'status' => 1,
            'cafe_id' => $cafe_id
        ];
        $response = ProductLogic::getProductList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Get(
     *     path="/product/search",
     *     tags={"Product"},
     *     description="搜索货品",
     *     operationId="search",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=false,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="keyword",
     *         in="query",
     *         description="关键字",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="limit",
     *         in="query",
     *         description="分页大小",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function search()
    {
        $limit = $this->limit;
        $keyword = $this->keyword;
        $data = [
            'keyword' => $keyword,
            'limit' => $limit
        ];
        $response = ProductLogic::search($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}